package procilege.impl.formatter;

import javax.xml.namespace.QName;

import merisis.sense.SenseMaker;

import com.google.inject.Inject;

import procilege.compute.ExprFormatTraveller;
import procilege.compute.PlaceTypeMetadata;
import procilege.compute.PlaceType;
import procilege.impl.NameImpl;

@PlaceTypeMetadata(type = NameImpl.class)
public class NameFormatter implements PlaceType<ExprFormatTraveller> {

	@Inject
	private SenseMaker nr;

	public void visit(ExprFormatTraveller tr, Object place) {

		StringBuilder sb = tr.getBuilder();
		NameImpl n = (NameImpl) place;
		QName qn = nr.introspect(n.nameId);

		String prefix = tr.assignNamePrefix(qn);
		if (prefix != null) {
			sb.append(prefix);
			sb.append(':');
		}
		sb.append(qn.getLocalPart());
	}
}